package spring.pojo2;

interface Fruit{
    void eat();
}
class Apple implements Fruit{

    @Override
    public void eat() {
        System.out.println("吃苹果");
    }
}
class Orange implements Fruit{

    @Override
    public void eat() {
        System.out.println("吃橘子");
    }
}
class factory {
    public static Fruit getInstance(String className){
        Fruit f=null;
        try {
            f=(Fruit) Class.forName(className).newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return f;
    }
}
public class client{
    public static void main(String[] args) {
        Fruit f=factory.getInstance("spring.pojo2.Orange");
        f.eat();
    }
}